import aiohttp
import asyncio

async def crawl_user_webappId(url,headers,payload):
    async with aiohttp.ClientSession() as session:
         async with session.post(url, headers=headers, json=payload) as response:
            html = await response.json()
            user_webappid_list= []
            if len(html["data"]["records"]) > 0:
                for tool_info in html["data"]["records"]:
                    webappId = tool_info["webappId"]
                    # print(webappId)
                    user_webappid_list.append(webappId)
            return user_webappid_list

if __name__ == "__main__":
    userId = input("请输入用户ID:")
    if not userId:
        userId = "1905156482181050370"
    user_list_url = "https://www.runninghub.cn/api/webapp/user/list"
    headers = {
        'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',
        'referer':'https://www.runninghub.cn/user-center',
        'authorization':'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxOTA1MTU2NDgyMTgxMDUwMzcwIiwiZXhwIjoxNzY0Mzk3MTMxLCJjcmVhdGVkIjoxNzYxODA1MTMxNjYyLCJ1c2VybmFtZSI6IjlkMzBmMTYwMzJmMTc5OTMzYTUyOGU2ZWRhM2IxZWJkIiwidXNlclJlZ2lvbiI6InpoX0NOIn0.g345EDg5Zz-7L9PeANhVWSrbczRRXeh_3-QlCY3FVxyDn9HRQ0kXAa1dTQhjgW2x8F9XEYPamrPukPh_xpckiQ',
        'Content-Type': 'application/json'
    }
    payload = {
        "size": 30,
        "current": 1,
        "userId": userId,
        "reloadData":"false"
    }
    
    user_webappid_list = asyncio.run(crawl_user_webappId(user_list_url,headers,payload))
    print(f"当前用户的webappid是:{user_webappid_list}")